{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-07-11T10:49:14.766846Z",
     "start_time": "2020-07-11T10:49:14.348963Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "      <th>frequency</th>\n",
       "      <th>RAM</th>\n",
       "      <th>size</th>\n",
       "      <th>disk</th>\n",
       "      <th>SSD</th>\n",
       "      <th>GPU</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>18200</td>\n",
       "      <td>2.6</td>\n",
       "      <td>16</td>\n",
       "      <td>15.4</td>\n",
       "      <td>512</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4999</td>\n",
       "      <td>1.8</td>\n",
       "      <td>4</td>\n",
       "      <td>13.6</td>\n",
       "      <td>512</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3699</td>\n",
       "      <td>1.6</td>\n",
       "      <td>4</td>\n",
       "      <td>13.0</td>\n",
       "      <td>1024</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9999</td>\n",
       "      <td>1.6</td>\n",
       "      <td>8</td>\n",
       "      <td>14.0</td>\n",
       "      <td>256</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8599</td>\n",
       "      <td>2.2</td>\n",
       "      <td>8</td>\n",
       "      <td>15.6</td>\n",
       "      <td>1024</td>\n",
       "      <td>no</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>23000</td>\n",
       "      <td>2.2</td>\n",
       "      <td>32</td>\n",
       "      <td>15.6</td>\n",
       "      <td>1024</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>4699</td>\n",
       "      <td>2.3</td>\n",
       "      <td>8</td>\n",
       "      <td>13.3</td>\n",
       "      <td>256</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2999</td>\n",
       "      <td>2.6</td>\n",
       "      <td>4</td>\n",
       "      <td>13.0</td>\n",
       "      <td>256</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   price  frequency  RAM  size  disk  SSD  GPU\n",
       "0  18200        2.6   16  15.4   512  yes  yes\n",
       "1   4999        1.8    4  13.6   512  yes  yes\n",
       "2   3699        1.6    4  13.0  1024   no   no\n",
       "3   9999        1.6    8  14.0   256  yes   no\n",
       "4   8599        2.2    8  15.6  1024   no  yes\n",
       "5  23000        2.2   32  15.6  1024  yes  yes\n",
       "6   4699        2.3    8  13.3   256  yes   no\n",
       "7   2999        2.6    4  13.0   256  yes   no"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df=pd.read_csv('笔记本集合.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "      <th>frequency</th>\n",
       "      <th>RAM</th>\n",
       "      <th>size</th>\n",
       "      <th>disk</th>\n",
       "      <th>SSD</th>\n",
       "      <th>GPU</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [price, frequency, RAM, size, disk, SSD, GPU]\n",
       "Index: []"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[(df['price']<=8000)&(df['size']>=14)&(df['RAM']>=8)&(df['GPU']=='yes')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "      <th>frequency</th>\n",
       "      <th>RAM</th>\n",
       "      <th>size</th>\n",
       "      <th>disk</th>\n",
       "      <th>SSD</th>\n",
       "      <th>GPU</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4999</td>\n",
       "      <td>1.8</td>\n",
       "      <td>4</td>\n",
       "      <td>13.6</td>\n",
       "      <td>512</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>4699</td>\n",
       "      <td>2.3</td>\n",
       "      <td>8</td>\n",
       "      <td>13.3</td>\n",
       "      <td>256</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   price  frequency  RAM  size  disk  SSD  GPU\n",
       "1   4999        1.8    4  13.6   512  yes  yes\n",
       "6   4699        2.3    8  13.3   256  yes   no"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[(df['price']<=8000)&(df['size']>13)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "      <th>frequency</th>\n",
       "      <th>RAM</th>\n",
       "      <th>size</th>\n",
       "      <th>disk</th>\n",
       "      <th>SSD</th>\n",
       "      <th>GPU</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [price, frequency, RAM, size, disk, SSD, GPU]\n",
       "Index: []"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[(df['price']<=8000)&(df['size']>=14)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 利用bool的series特性判断bool_set1是不是bool_set2的子集\n",
    "def is_subset(bool_set1, bool_set2):\n",
    "    return ((bool_set1&bool_set2)==bool_set1).sum()==bool_set1.shape[0]\n",
    "\n",
    "def MinRelax(df, REQ):\n",
    "    MinRS=[]\n",
    "    PQRS=pd.DataFrame(REQ)\n",
    "    for i in range(df.shape[0]):\n",
    "        p=df.iloc[i]\n",
    "        ISX=PQRS[i]\n",
    "\n",
    "        # 判断当前MinRelax中是否存在元素是当前ISX的子集-》反了\n",
    "    #     SUB=[r for r in MinRS if is_subset(r,ISX)]\n",
    "        SUB=[r for r in MinRS if is_subset(ISX,r)]\n",
    "        if len(SUB)!=0:continue\n",
    "\n",
    "    #     SUPER=[r for r in MinRS if is_subset(ISX,r)]\n",
    "        SUPER=[r for r in MinRS if is_subset(r,ISX)]\n",
    "        if len(SUPER)>0:\n",
    "            MinRS=[r for r in MinRS if [(r==r2).all() for r2 in SUPER][0] ]\n",
    "    #         MinRS=[r for r in MinRS if r not in SUPER]\n",
    "        MinRS.append(ISX)\n",
    "    return MinRS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[price    False\n",
       " size      True\n",
       " RAM       True\n",
       " GPU       True\n",
       " Name: 0, dtype: bool,\n",
       " price     True\n",
       " size     False\n",
       " RAM      False\n",
       " GPU       True\n",
       " Name: 1, dtype: bool,\n",
       " price     True\n",
       " size     False\n",
       " RAM       True\n",
       " GPU      False\n",
       " Name: 6, dtype: bool]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "REQ=[(df['price']<=8000),(df['size']>=14),(df['RAM']>=8),(df['GPU']=='yes')]\n",
    "MinRelax(df, REQ)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
